//
//  Macros.h
//  DDSocial
//
//  Created by 阿帕  on 2018/7/2.
//  Copyright © 2018年 XY. All rights reserved.
//

#ifndef Macros_h
#define Macros_h

#define GAODEMAP_KEY @"6ba9aa5cbbe930fd68e855952db82ad7"//高德地图key
//#define GAODEMAP_KEY @"2460b3b80e895be6d883f0ecbfc0ec49"//高德地图key点运通
#define JIGUANG_APPKEY @"199196b41eccd5db9597cb83"//极光APPkey
#define Default_BranchCode @"49adb23841asw3118yunnanchenggang"//机构编码
#define Default_Tel @""//默认座机
#define Theme_ColorValueString @"#00a99d" //主题颜色色值
#define APP_PlatformName @"运八"//平台名称

/**
 百度人脸识别开启/关闭
 */
//#define isOpenBaiDuFaceSDK

/**
 省平台上报测试开关
 */
//#define isTestSPT
#define SPTIsParams YES
#define SPTIsRelease NO
#define SPTAppSecurity @""
#define SPTEnterpriseSenderCode @""
#define SPTAppId @""

/**
 是否是线上环境（屏蔽一些功能,比如版本更新检测、修改测试地址）
 */
#define isProductionEnvironment


///app build版本
#define VERSION_CODE [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
///app版本
#define VERSION_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

#define APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

#define APP_BUNDLEID [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]

#define LBXScan_Define_Native  //下载了native模块
#define LBXScan_Define_UI     //下载了界面模块

#define VERSION @"v1.0"
//上拉加载默认条目
#define DEFULT_LOAD_NUM @"10"
///按钮圆角 border-radius
#define BTN_BORDER_RADIUS 5

#define TOKEN [UserDefaultUtil valueForKey:USER_TOKEN]

/** 屏幕高度 */
#define ScreenH [UIScreen mainScreen].bounds.size.height
/** 屏幕宽度 */
#define ScreenW [UIScreen mainScreen].bounds.size.width

/** 弱引用 */
#define WEAKSELF __weak typeof(self) weakSelf = self;


/******************    TabBar          *************/
#define MallClassKey   @"rootVCClassString"
#define MallTitleKey   @"title"
#define MallImgKey     @"imageName"
#define MallSelImgKey  @"selectedImageName"

/***************** 轮播图片宽高比  ******************/
#define Banner_Ratio 0.37
#define DefaultLocationTimeout 10
#define DefaultReGeocodeTimeout 5

/*****************  屏幕适配  ******************/

#define SX(width)(float) (width)/375*ScreenW
#define SY(height)(float) (height)/667*ScreenH

#define SP_Width (ScreenW/375.0f)
//iphoneX 宽高比: 9:19.488 (320)
#define SP_Height (iphoneX ? (ScreenH/692.9f) : (ScreenH/667.0f))

//不同版本比例系数
#define PROPORTION6 (ScreenW/375.f)
#define PROPORTION6P (ScreenW/414.f)

#define kP6(pt) (pt*PROPORTION6)
#define kP6p(pt) (pt*PROPORTION6P)

//判断是否是ipad
#define dIsPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
//判断iPhone5系列
#define kiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) && !dIsPad : NO)
//判断iPhone6 6s 7系列
#define kiPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) && !dIsPad : NO)
//判断iPhone6p 6sp 7p系列
#define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) && !dIsPad : NO)
//判断iPhoneX，Xs（iPhoneX，iPhoneXs）
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !dIsPad : NO)
//判断iPhoneXr
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !dIsPad : NO)
//判断iPhoneXsMax
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size)&& !dIsPad : NO)

//判断是否是刘海屏
#define iphoneX ({ \
    BOOL iPhoneX = NO; \
    if (@available(iOS 11.0, *)) { \
        if ([UIApplication sharedApplication].windows[0].safeAreaInsets.bottom > 0) { \
            iPhoneX = YES; \
        } \
    } \
    iPhoneX; \
})


//判断iPhoneX所有系列
//#define iphoneX  (IS_IPHONE_X || IS_IPHONE_Xr || IS_IPHONE_Xs_Max)
#define iphone6p (ScreenH == 763)
#define iphone6 (ScreenH == 667)
#define iphone5 (ScreenH == 568)
#define iphone4 (ScreenH == 480)
/*****************  设备控件高度  ******************/
#define NavHeight (iphoneX ? 88.0 : 64.0)//导航栏高度
#define TabBarHeight (iphoneX ? 83.0 : 49.0)//tabBar高度
#define StatusBarHeight (iphoneX ? 44.0 : 20.0)//状态栏高度
#define MenuBarHeight (iphoneX?34:0)//底部菜单高度

//色值
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)

#define HEXCOLOR(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 green:((float)((hex & 0xFF00) >> 8)) / 255.0 blue:((float)(hex & 0xFF)) / 255.0 alpha:1]

//全局背景色
#define DCBGColor RGB(245,245,245)

#define PFR [[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0 ? @"PingFangSC-Regular" : @"PingFang SC"

#define APPDELEGATE ((AppDelegate *)[UIApplication sharedApplication].delegate)
//通知中心
#define KNotificationCenter [NSNotificationCenter defaultCenter]

#define Theme_ColorValue [UIColor cy_colorWithHexString:Theme_ColorValueString] //主题颜色

#define BackgroundColor [UIColor cy_colorWithHexString:@"#F1F1F1"] //背景色值

#define Green_Color [UIColor cy_colorWithHexString:@"#35AA47"] //绿色

#define Red_Color [UIColor cy_colorWithHexString:@"#FF2400"] //红色

#define Orange_Color [UIColor cy_colorWithHexString:@"#FB6243"] //橘黄

#define Golden_Color [UIColor cy_colorWithHexString:@"#FFC809"] //金黄

#define Red_TextColor [UIColor cy_colorWithHexString:@"#ff6a57"] //红色字体

#define Dark_TextColor [UIColor cy_colorWithHexString:@"#4C5C72"] //深色字体颜色

#define Light_TextColor [UIColor cy_colorWithHexString:@"#96A0B9"] //浅色字体颜色

#define Line_TextColor [UIColor cy_colorWithHexString:@"#e9eaec"] //分割线颜色

// 字符串拼接
#define CJStringWithFormat(format,...)[NSString stringWithFormat:format,##__VA_ARGS__]
//字符串是否为空
#define IsStrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref)isEqualToString:@""]))
//数组是否为空
#define IsArrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref) count] == 0))

#define StringCheck(value) ((NSString *)([value isKindOfClass:[NSString class]] ? value : \
                            [value isKindOfClass:[NSNumber class]] ? [(NSNumber *)value stringValue] : @""))
#define NumberCheck(value) ((NSNumber *)([value isKindOfClass:[NSNumber class]] ? value : \
                            [value isKindOfClass:[NSString class]] ? [NSNumber numberWithInteger:((NSString *)(value)).integerValue] : @0))

#define ArrayCheck(value) ((NSArray *)([value isKindOfClass:[NSArray class]] ? value : @[]))
#define DictionaryCheck(value) ((NSDictionary *)([value isKindOfClass:[NSDictionary class]] ? value : @{}))
// 存取 shan
#define CJSaveMyDefault(key,value) [[NSUserDefaults standardUserDefaults] setObject:value forKey:key]
#define CJFetchMyDefault(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]
#define CJRemoveMyDefault(key) [[NSUserDefaults standardUserDefaults] removeObjectForKey:key]

// View 圆角
#define ViewRadius(View, NRadius)\
\
[View.layer setCornerRadius:(NRadius)];\
[View.layer setMasksToBounds:YES];

// View 圆角和加边框
#define ViewBorderRadius(View, NRadius, Width, Color)\
\
[View.layer setCornerRadius:(NRadius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]];

/**<
 字体大小
 */
#define font(num) [UIFont systemFontOfSize:(num*SP_Width)]

/**<
 字体大小加粗
 */
#define boldFont(num) [UIFont boldSystemFontOfSize:num]

/**<
 设置本地图片
 */
#define image(name) [UIImage imageNamed:name]

/**<
 SD加载图片 传入自己、图片地址、本地图片名称
 */
#define setNetImage(self,urlStr,imgName) [self sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:imgName]];

/**<
 裁剪圆角
 */
#define cut(self,size) self.layer.masksToBounds = YES; self.layer.cornerRadius = size;

/**<
 设置边框颜色和宽度
 */
#define cutBorder(self,size,color) self.layer.borderWidth = size; self.layer.borderColor = [UIColor cy_colorWithHexString:color].CGColor;

/**<
 打客服电话
 */
#define CALL_PHONE(phone) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]] options:@{} completionHandler:^(BOOL success){}];

/**<
 设置IQKeyboardManager
 */
#define KEYBOARDMANAGER IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager];   keyboardManager.enable = YES;  keyboardManager.shouldResignOnTouchOutside = YES;  keyboardManager.shouldToolbarUsesTextFieldTintColor = YES;  keyboardManager.previousNextDisplayMode = IQPreviousNextDisplayModeDefault;  keyboardManager.enableAutoToolbar = YES;  keyboardManager.shouldShowToolbarPlaceholder = NO;

//判断token是否为空
#define TOKEN_ISEMPTY ([UserDefaultUtil valueForKey:USER_TOKEN] == nil || [[UserDefaultUtil valueForKey:USER_TOKEN] isEqual:@""])

///Log
#ifdef DEBUG
#define DebugLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String])
//#define DebugLog(...) printf("%f %s\n",[[NSDate date]timeIntervalSince1970],[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
#else
#define DebugLog(format, ...)
#endif

/**<
 自定义键值
 */

//保存登录返回信息
#define USER_PHONE @"LogInResponseUserPhone"
#define USER_CODE @"LogInResponseUsercode"
#define USER_PASSWORD @"LogInResponseUserPassWord"
#define USER_TOKEN @"LogInResponseAccessToken"
#define USER_Start_DIC @"LogInResponseAccessInfoDic"
#define CJLogInResponseBranch @"CJLogInResponseBranch"
#define CJLogInResponseToken @"LogInResponseAccessToken"
#define HOME_OILPAYTYPE @"MyOilPayType"
#define Login_Branch @"LoginBranch"
#define Branch_Salt @"BranchSalt"///默认机构盐值
#define IsLoginNeedSMS @"no"///登录是否需要验证码
#define UserPartyCode @"UserPartyCode" /// PartyCode

///网点编码
#define BranchCode @"BranchCode"

///位置上报code
#define LocationBranchCode @"LocationBranchCode"

#define DRIVER_TYPE @"MyDriverType"
///经度
#define LONGITUDE @"longitude"
///纬度
#define LATITUDE @"latitude"

#define WEBSITE @"website"//官网

#define CustomerTel @"customerTel"//客服电话
#define CustomerLine @"complainLine"

///微信名
#define WECHAT_NAME @"wechatName"

#define WECHAT_AVATAR @"avatar"

///
#define WECHAT_UNIONID @"unionId"
///
#define WECHAT_OPENID @"openId"

#define IS_PARTNER @"isPartner"

#define Auth_Valid @"Auth_Valid"

#define isOpenJCSaasModule @"isOpenJCSaasModule"

#define DriverPartyCode @"DriverPartyCode"

#define userDriverCode @"userDriverCode"

#define Identity_CarCaptain [[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 1
#define Identity_Driver ([[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 0 || [[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 2)
#define Alone_Driver [[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 0
#define CarCaptain_Driver [[UserDefaultUtil valueForKey:DRIVER_TYPE] integerValue] == 2

typedef void(^CJBlock)(id anyObject);
#define CJTableToTopHeight 0  // tableview 顶部的间距
#define CJToLeftMargin   15  // 距离左右边距的距离
#define CJToViewMarginH  10  // 两个view 之间的模块分割
#define CJCellTopPadding  5  //
#define CJLineHeight      1
#define CJUICornerWidth   1
#define CJUICutCorner     5 // 圆角
// yeufeu
#define CJCellLabHeight     LW(40)  //labxiashi gaodu
#define CJCellTwoLabPadding  LW(3)

#define CJAlertDueTag 2021110
#define CJBottomBtnHeight 44

#endif 
